{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "284b7349-b14a-4edf-b5a6-daacd0979642",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3, 4, 6, 6, 6, 9, 9, 9, 9, 9]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = [3, 4, 6, 2, 1, 9, 0, 7, 5, 8]\n",
    "list(accumulate(data, max))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "c5774a66-4b60-4d7b-ae36-56e641a4d2d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'b', 'c', 'd', 'e', 'f']"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c1 =itertools.chain(\"abc\", \"def\")\n",
    "list(c1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "a89da351-287c-4260-b7b1-b4b9cd6d4fb5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n"
     ]
    }
   ],
   "source": [
    "def generator1():\n",
    "    yield from range(3)\n",
    "\n",
    "def generator2():\n",
    "    yield from range(3, 6)\n",
    "\n",
    "chain_iterator = itertools.chain(generator1(), generator2())\n",
    "\n",
    "for item in chain_iterator:\n",
    "    print(item)\n",
    "# 输出：\n",
    "# 0\n",
    "# 1\n",
    "# 2\n",
    "# 3\n",
    "# 4\n",
    "# 5\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "876dfe85-9ee2-4547-8961-65ccd6640897",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Py(Python note)",
   "language": "python",
   "name": "pynote"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
